package logic

import (
	"context"
	"fmt"
	"house_srv/models"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源发布
func (l *HouseAddLogic) HouseAdd(in *house.HouseAddRequest) (*house.HouseAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	houses := models.House{
		UserId:   in.UserId,
		Title:    in.Title,
		MinPrice: float64(in.MinPrice),
		MaxPrice: float64(in.MaxPrice),
		Price:    float64(in.Price),
		Address:  in.Address,
		Image:    in.Image,
		Size:     in.Size,
	}
	if err = houses.HouseAdd(); err != nil {
		logx.Errorf("用户添加失败")
		return nil, fmt.Errorf("用户添加失败")
	}

	return &house.HouseAddResponse{
		Id: int64(houses.ID),
	}, nil
}
